package com.example.demo.repository;

import com.example.demo.entity.TeacherClassEntity;
import com.example.demo.entity.vo.TeacherClassVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author xzy
 * @date 2020-11-04 11:33
 * 说明：
 */
@Repository
public interface TeacherClassRepository extends JpaRepository<TeacherClassEntity, String>, JpaSpecificationExecutor<TeacherClassEntity> {

    /**
     * 查询所有教师对应的班级信息
     *
     * @return 所有教师对应的班级信息
     */
    @Query(" select " +
            "    new com.example.demo.entity.vo.TeacherClassVO(t,c) " +
            "from " +
            "    TeacherEntity t " +
            "left join TeacherClassEntity tc on tc.teacherId = t.id " +
            "left join ClassEntity c on c.id = tc.classId")
    List<TeacherClassVO> getAllTeacher2Class();
}
